#include <iostream>
#include <string.h>
using namespace std;
class Base{
public:
    Base(const char *base)
    :_base(new char[strlen(base)+1]())
    {
        strcpy(_base,base);
        cout<<"Base(const char *)"<<endl;
    }
    virtual
        ~Base(){
            cout<<"~Base"<<endl;
            if(_base){
                delete [] _base;
                _base = nullptr;
            }
        }
    virtual void print()
    {
        cout<<"Base::print()"<<endl;
    }
private:
    char * _base;
};
class Derived : public Base{
public:
    Derived(const char * base,const char * derived)
    :Base(base)
    ,_derived(new char[strlen(derived)+1]())
    {
      cout<<"Derived(const char * derived)"<<endl;
      strcpy(_derived,derived);
    }
    ~Derived(){
        cout<<"~Derived"<<endl;
        if(_derived){
            delete [] _derived;
            _derived = nullptr;
        }
    }
    void print() override{
        cout << "Derived::print()"<<endl;
    }
private:
    char * _derived;
};
void test(){
  Derived d("hello","world");
  Base * pbase = &d;
  pbase ->print();
}
void test2(){
    Base * pbase2 = new Derived("hello","world");
    pbase2->print();
    delete  pbase2;
}
int main()
{
    test();
    return 0;
}

